// src/mock/index.ts
import Mock from 'mockjs';
import menuData from '@/mock/mockData/menuData';
import loginData from '@/mock/mockData/loginData' ;
import permissionData from '@/mock/mockData/permissionData' ;

/*
Mock.mock(/menu/, 'get', (req: any) => {
  return menuData.data;
});
*/
Mock.mock(/menu/, 'get', (options) => {
  const { url } = options;

  // 使用 URLSearchParams 解析查询字符串
  const queryParams = new URLSearchParams(new URL(url).search);
  const username = queryParams.get('username');
  const password = queryParams.get('password');

  // console.log('username:', username);
  // console.log('password:', password);

  return menuData({ username, password });
});

// 权限接口
Mock.mock(/permission/, 'get', (options) => {
  const { url } = options;

  // 使用 URLSearchParams 解析查询字符串
  const queryParams = new URLSearchParams(new URL(url).search);
  const username = queryParams.get('username');
  const password = queryParams.get('password');

  // console.log('username:', username);
  // console.log('password:', password);

  return permissionData({ username, password });
});


/*
Mock.mock(/login/, 'post', (req: any) => {
  return loginData.data;
});
*/
//  /\/ zheng'zhi'fa'zhe
Mock.mock(/\/login/, (options) => {
  const { body } = options;
  const data = JSON.parse(body); // 解析请求体中的数据
  return loginData(data); // 调用动态生成的登录数据函数
});